package com.dsfa.biz.dataCenter;

import cn.hutool.core.date.DateTime;
import com.dsfa.platform.starter.db.jfinal.kit.Kv;
import com.dsfa.platform.starter.db.jfinal.plugin.activerecord.Db;
import com.dsfa.platform.starter.db.jfinal.plugin.activerecord.Record;
import org.springframework.stereotype.Service;

/**
 * @Description: 数据中台相关数据操作
 * @ClassName: StartWS
 * @Author: wangdm
 * @Date: 2024/1/13
 */
@Service
public class DataCenterService {
    private static final String SQL_KEY = "biz.dataCenter.";

    /**
     * @Description: 根据id获取被代理的地址
     * @Author: wangdm
     * @Date: 2024/1/26
     */
    public Record getTargetInfoById(String id) {
        return Db.findFirst(Db.getSqlPara(SQL_KEY + "getTargetInfoById", Kv.by("id", id)));
    }

    /**
     * @Description: 保存日志记录
     * @Author: wangdm
     * @Date: 2024/1/25
     */
    public boolean saveAgentWSLog(Record record) {
        return Db.save("dgp_dq_agent_ws_log", record);
    }

    /**
     * @Description: 更新响应结果
     * @Author: wangdm
     * @Date: 2024/1/25
     */
    public boolean setAgentWSLogResponse(String id, int respTime, String repData, String remark,int status) {
        Record r = new Record();
        r.set("dgp_dq_agent_ws_log_id", id)
                .set("rep_data", repData)
                .set("rep_status", status)
                .set("resp_time", respTime)//响应时长
                .set("remark", remark)//解析时有错误
                .set("req_end_time", DateTime.now());
        return Db.update("dgp_dq_agent_ws_log","dgp_dq_agent_ws_log_id", r);
    }
}
